package vg.com.frame;

import vg.com.chatonline.activity.R;
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kdstudio.network.URLCachePolicy;
import com.kdstudio.network.URLRequest;
import com.kdstudio.network.URLRequestDelegate;
import com.kdstudio.network.reponse.URLBitmapResponse;

public class yahoo_frame extends LinearLayout{

	TextView tv_name,tv_status;
	ImageView img_user;
	LinearLayout contenLayout;
	private Handler mHanlder;
	public yahoo_frame(Context context) {
		super(context, null);
		// TODO Auto-generated constructor stub
	}
	
	public yahoo_frame(Context context, AttributeSet attrs) {
		super(context, attrs);		
		String service=Context.LAYOUT_INFLATER_SERVICE;
		LayoutInflater li=(LayoutInflater)context.getSystemService(service);
		View v=li.inflate(R.layout.list_yahoo, null);
//		setContenLayout((LinearLayout)v.findViewById(R.id.layout_id));
		setTv_name((TextView)v.findViewById(R.id.tv_name));
		setImg_user((ImageView)v.findViewById(R.id.img_yh));
		setTv_status((TextView)v.findViewById(R.id.tv_status));
		int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
		this.addView(v,new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, screenWidth/8));
	}
	
	public void fillData(String name,String url,String status)
	{
		mHanlder=new Handler();
		//khoi tao request gui lenh den server
		URLRequest request=new URLRequest(url,new httpBitmapRequestDelegate());
		//gui va lay theo kieu gi(Json hay BitMap)
		request.setReponse(new URLBitmapResponse());
		//set che do cache cua request
		request.setCachePolicy(URLCachePolicy.LOCAL);
		request.send();
		getTv_name().setText(name);
		getTv_status().setText(status);
		String tv=getTv_status().toString();
	}

	public TextView getTv_name() {
		return tv_name;
	}

	public void setTv_name(TextView tv_name) {
		this.tv_name = tv_name;
	}

	public ImageView getImg_user() {
		return img_user;
	}

	public void setImg_user(ImageView img_user) {
		this.img_user = img_user;
	}

	public LinearLayout getContenLayout() {
		return contenLayout;
	}

	public void setContenLayout(LinearLayout contenLayout) {
		this.contenLayout = contenLayout;
	}
	

	public TextView getTv_status() {
		return tv_status;
	}

	public void setTv_status(TextView tv_status) {
		this.tv_status = tv_status;
	}


	public class httpBitmapRequestDelegate extends URLRequestDelegate
	{
		@Override
		public void onRequestReponse(URLRequest httpRequest) {
			// TODO Auto-generated method stub
			//kieu can response(Json hay BitMap)
			final URLBitmapResponse response=(URLBitmapResponse)httpRequest.getReponse();
			mHanlder.post(new Runnable() {
				
				public void run() {
					// TODO Auto-generated method stub
					//set anh
					getImg_user().setImageBitmap(response.bitmap);
				}
			});
			
			super.onRequestReponse(httpRequest);
		}
	}
	
	
}
